"""
【命令单独组合】
命令模式(Command Pattern)
一个请求封装成一个对象，从而可将请求的发送者和接收者解耦。这个模式允许使用不同的请求来参数化对象，将请求排队或记录请求日志，以及支持可撤销的操作。

请求执行交给命令，实际操作有单独类，再结合成具体类，由一个统一类收集并选择调用
"""
from abc import ABC, abstractmethod


class Command(ABC):
    @abstractmethod
    def execute(self):
        pass

    @abstractmethod
    def undo(self):
        pass


class Light:
    def on(self):
        print("Light is on")

    def off(self):
        print("Light is off")


class LightOnCommand(Command):
    def __init__(self, light):
        self.light = light

    def execute(self):
        self.light.on()

    def undo(self):
        self.light.off()


class LightOffCommand(Command):
    def __init__(self, light):
        self.light = light

    def execute(self):
        self.light.off()

    def undo(self):
        self.light.on()


class RemoteControl:
    def __init__(self):
        self.commands = []

    def add_command(self, command):
        self.commands.append(command)

    def execute_commands(self):
        for command in self.commands:
            command.execute()


light = Light()
light_on_command = LightOnCommand(light)
light_off_command = LightOffCommand(light)

remote_control = RemoteControl()
remote_control.add_command(light_on_command)
remote_control.add_command(light_off_command)

remote_control.execute_commands()
"""
Light is on
Light is off
"""
